package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.UserCoupon;
import com.example.vo.UserCouponVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author circle48
* @description 针对表【user_coupon(用户优惠券关联表)】的数据库操作Mapper
* @createDate 2024-05-28 20:53:44
* @Entity com.example.entity.UserCoupon
*/
public interface UserCouponMapper extends BaseMapper<UserCoupon> {
    IPage<UserCouponVO> selectUserCoupons(Page<?> page, @Param("userId") Long userId, @Param("status") String status);

    Boolean isCouponCollected(Long userId, Long couponId);


    List<UserCouponVO> getCouponsByIds(List<Long> couponIds);


    @Update("UPDATE user_coupon SET order_id = #{orderId}, order_sn = #{orderSn},status=1 WHERE id = #{couponId}")
    void updateCouponStatusToUsed(@Param("couponId") Long couponId, @Param("orderId") Long orderId, @Param("orderSn") String orderSn);

    @Update("UPDATE user_coupon SET order_id = NULL, order_sn = NULL, status = 0 WHERE id = #{couponId}")
    void updateCouponStatusToUnUsed(@Param("couponId") Long couponId);
}




